package org.mysfit.ctp4j.infra.pojo;

import java.io.Serializable;

/**
 * 
 * @author long.gf
 *
 * @param <T>
 */
public class ApiResponse<T> implements Serializable {

	private static final long serialVersionUID = -8030837742651068921L;

	private T data;
	private Integer code;
	private String msg;
	
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public static ApiResponse<String> ok(){
		ApiResponse<String> resp = new ApiResponse<String>();
		resp.setCode(200);
		resp.setData("success");
		return resp;
	}
	
	public static <T> ApiResponse<T> ok(T data) {
		ApiResponse<T> resp = new ApiResponse<T>();
		resp.setCode(200);
		resp.setData(data);
		return resp;
	}
	
	public static <T> ApiResponse<T> error(Throwable e) {
		ApiResponse<T> resp = new ApiResponse<T>();
		resp.setCode(500);
		resp.setMsg(e.getMessage());
		return resp;
	}
}
